package com.air.designmodel.six.controller;

import com.air.designmodel.six.common.CommonPairResponse;
import com.air.designmodel.six.common.FormSubmitRequest;
import com.air.designmodel.six.service.FormService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;

/**
 * @author shent
 */
@RestController()
@RequestMapping("/simple")
public class SimpleController {
    @Autowired
    private FormService formService;

    @PostMapping("/form/submit")
    public CommonPairResponse<String, Serializable> submitForm(String submitType, String formInputJson) {
        JSONObject formInput = JSON.parseObject(formInputJson);
        FormSubmitRequest request = new FormSubmitRequest();
        request.setUserId(123456L);
        request.setSubmitType(submitType);
        request.setFormInput(formInput);
        return formService.submitForm(request);
    }

    @GetMapping("/str")
    public String getStr() {
        return "hello";
    }

}
